/*
https://leetcode-cn.com/problems/beautiful-arrangement-ii/solution/you-mei-de-pai-lie-ii-by-leetcode/
 */
import java.util.Arrays;

public class Solution667 {
    public int[] constructArray(int n, int k) {
        int[] ans=new int[n];
        for (int i=0;i<n-k;i++){
            ans[i]=i+1;
        }
        int r=n,l=n-k+1;
        for (int i=0;i<k;i++){
            if (i%2==0) {
                ans[i+n-k]=r;
                r--;
            }else {
                ans[i+n-k]=l;
                l++;
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution667().constructArray(6,3)));
    }
}
